package com.gf.pf.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gf.pf.dao.MyBatisDao;
import com.gf.pf.mapper.UserMapper;
import com.gf.pf.model.User;
import com.gf.pf.model.UserJob;
import com.gf.pf.model.UserRole;
import com.gf.pf.service.UserService;

/**
 * @describe 用户
 * @date     2015年3月7日
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {

	@Autowired
	private UserMapper userMapper;
	
	/**
	 * 用于XML
	 */
	@Autowired
	private MyBatisDao myBatisDao;

	/* (non-Javadoc)
	 * @see com.gf.pf.service.UserService#findUser(java.util.Map)
	 * 根据用户名、密码查询用户
	 */
	@Override
	public User getUser(Map<String, Object> param) {
		return userMapper.getUser(param);
	}
	
	/* (non-Javadoc)
	 * @see com.gf.pf.service.UserService#findUser(java.util.Map)
	 * 根据用户名、密码查询用户
	 */
	@Override
	public User getUserForXml(User user) {
		return (User)myBatisDao.get("pf.user.getUserLogin", user);
	}

	/* (non-Javadoc)
	 * @see com.gf.pf.service.UserService#getUserByDepId(java.lang.String)
	 * 查询部门下的所有用户
	 */
	@Override
	public List<User> getUserByDepId(String depId) {
		return userMapper.getUserByDepId(depId);
	}

	/* (non-Javadoc)
	 * @see com.gf.pf.service.UserService#modifyUser(java.util.Map)
	 * 修改密码
	 */
	@Override
	public Integer modifyUserPassword(User user) {
		return userMapper.modifyUserPassword(user);
	}

	/* (non-Javadoc)
	 * @see com.gf.pf.service.UserService#saveUser(com.gf.pf.model.User)
	 * 保存用户
	 */
	@Override
	public Integer saveUser(User user) {
		return userMapper.saveUser(user);
	}

	/* (non-Javadoc)
	 * @see com.gf.pf.service.UserService#getUserById(java.lang.String)
	 * 根据用户Id查询用户信息
	 */
	@Override
	public User getUserById(String id) {
		return userMapper.getUserById(id);
	}

	/* (non-Javadoc)
	 * @see com.gf.pf.service.UserService#modifyUser(com.gf.pf.model.User)
	 * 修改用户信息
	 */
	@Override
	public Integer modifyUser(User user) {
		return userMapper.modifyUser(user);
	}

	/* (non-Javadoc)
	 * @see com.gf.pf.service.UserService#deleteUser(com.gf.pf.model.User)
	 * 删除用户
	 */
	@Override
	public Integer deleteUser(String userId) {
		return userMapper.deleteUser(userId);
	}

	/* (non-Javadoc)
	 * @see com.gf.pf.service.UserService#jobByUserId(java.lang.String)
	 * 根据用户id查询所属职位
	 */
	@Override
	public List<Map<String, String>> jobByUserId(String userId) {
		return userMapper.jobByUserId(userId);
	}

	/* (non-Javadoc)
	 * @see com.gf.pf.service.UserService#deleteJobByUser(java.lang.String)
	 * 根据用户id删除所包含的职位
	 */
	@Override
	public Integer deleteJobByUser(String userId) {
		return userMapper.deleteJobByUser(userId);
	}

	/* (non-Javadoc)
	 * @see com.gf.pf.service.UserService#saveJobByUser(java.lang.String, java.lang.String)
	 * 根据用户id保存所包含的职位
	 */
	@Override
	public Integer saveJobByUser(UserJob uj) {
		return userMapper.saveJobByUser(uj);
	}

	/* (non-Javadoc)
	 * @see com.gf.pf.service.UserService#roleByUserId(java.lang.String)
	 * 根据用户id查询所属角色
	 */
	@Override
	public List<Map<String, String>> roleByUserId(String userId) {
		return userMapper.roleByUserId(userId);
	}

	/* (non-Javadoc)
	 * @see com.gf.pf.service.UserService#deleteRoleByUser(java.lang.String)
	 */
	@Override
	public Integer deleteRoleByUser(String userId) {
		return userMapper.deleteRoleByUser(userId);
	}

	/* (non-Javadoc)
	 * @see com.gf.pf.service.UserService#saveRoleByUser(com.gf.pf.model.UserJob)
	 */
	@Override
	public Integer saveRoleByUser(UserRole ur) {
		return userMapper.saveRoleByUser(ur);
	}

	/* (non-Javadoc)
	 * @see com.gf.pf.service.UserService#resetUserPwd(com.gf.pf.model.User)
	 * 密码重置
	 */
	@Override
	public Integer resetUserPwd(User user) {
		return userMapper.resetUserPwd(user);
	}
	
}
